package org.tacademy.basic.calendar.databasemanager;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyDatabaseOpenHelper extends SQLiteOpenHelper {

	public final static String DB_NAME = "MyDB";
	public final static int DB_VERSION = 1;
	
	public MyDatabaseOpenHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, DB_NAME, null, DB_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		
		String sql = "CREATE TABLE " + 
					DBConstant.ScheduleTable.TABLE_NAME +"(" +
					DBConstant.ScheduleTable.ID + " integer primary key autoincrement," +
					DBConstant.ScheduleTable.TITLE + " text," +
					DBConstant.ScheduleTable.DATE + " text," +
					DBConstant.ScheduleTable.TIME + " text," +
					DBConstant.ScheduleTable.CONTENT + " text,"+
					DBConstant.ScheduleTable.LOCATION + " text)";
		db.execSQL(sql);
		
		Log.i("db", "db create");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
		// TODO Auto-generated method stub
		String sql = "DROP TABLE " + DBConstant.ScheduleTable.TABLE_NAME;
		db.execSQL(sql);
		onCreate(db);
		
		Log.i("db", "upgrade");
	}

}
